package client

import (
	"context"
	"github.com/ecodeclub/ekit/syncx/atomicx"
	"google.golang.org/grpc"
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	followv1 "jk-time/webook/api/proto/gen/follow/v1"
)

type FollowClient struct {
	followv1.FollowServiceClient
	downgrade atomicx.Value[bool]
}

func (f *FollowClient) GetFollowee(ctx context.Context, in *followv1.GetFolloweeRequest, opts ...grpc.CallOption) (
	res *followv1.GetFolloweeResponse, err error) {
	if f.downgrade.Load() {
		return nil, nil
	}
	defer func() {
		if status.Code(err) == codes.Unavailable {
			f.downgrade.Store(true)
		}
		go func() {
			//发心跳给follow检测，退出downgrade

		}()
	}()

	res, err = f.FollowServiceClient.GetFollowee(ctx, in, opts...)
	return
}
